package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.model.wmNewsDto.WmNewsDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体文章表(WmNews)表控制层
 *
 * @author makejava
 * @since 2022-04-12 16:02:39
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    /**
     * 服务对象
     */
    @Resource
    private WmNewsService wmNewsService;
    /**
     * 文章发布上传提交
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.submit(wmNewsDto);
    }

    /**
     * 自媒体文章列表
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto wmNewsPageReqDto) {
    return wmNewsService.list(wmNewsPageReqDto);
    }
    /**
     * 自媒体编辑
     */
    @GetMapping("/one/{newsId}")
    public ResponseResult one(@PathVariable("newsId") Long newsId){
        WmNews wmNews = wmNewsService.queryById(newsId);
        return ResponseResult.okResult(wmNews);
    }
    /**
     * 自媒体删除
     */
    @GetMapping("/del_news/{newsId}")
    public ResponseResult deleteById(@PathVariable("newsId") Long newsId){
        return wmNewsService.deleteById(newsId);
    }
}

